//
// Created by Tan Ke on 2023/12/18.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int countCharacters(char** words, int wordsSize, char* chars)
{
    int charsMap[26] = {0};
    int result = 0;

    for (int i = 0; i < wordsSize; i ++) {
        int success = 1;
        for (int m = 0; m < 26; m ++) {
            charsMap[m] = 0;
        }
        for (int m = 0; m < strlen(chars); m ++) {
            charsMap[chars[m] - 'a'] += 1;
        }

        for (int m = 0; m < strlen(words[i]); m ++) {
            charsMap[words[i][m] - 'a'] -= 1;
            if (charsMap[words[i][m] - 'a'] < 0) {
                success = 0;
                break;
            }
        }

        if (success == 1) {
            result += strlen(words[i]);
        }
    }

    return result;
}

int main(void)
{
    return 0;
}
